<?php

class ModelConfigManager {
	
	private static $_loadedConfig = array();
	
	public static function load($model) {
		$class = get_class($model);
		if(!isset(self::$_loadedConfig[$class])) {
			$reader = Yii::app()->config;
			$enumer = Yii::app()->enum;
			$rc = new ReflectionClass($model);
			while($rc) {
				$package = $enumer->lookup('modelPackage', $rc->name);
				$config = $reader->read('models.'.$package.'.'.$rc->name);
				if(!empty($config)) break;
				$rc = $rc->getParentClass();
			}
			self::$_loadedConfig[$class] = Yii::createComponent($config);
		}
		return self::$_loadedConfig[$class];
	}

}

?>